package com.heima.wemedia.controller.v1;


import com.heima.common.constants.wemedia.WemediaConstants;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDTO;
import com.heima.model.wemedia.pojos.WmMaterial;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.awt.font.MultipleMaster;

@Api(value = "上传文件的借口" , tags = "上传文件的借口")
@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;


    @ApiOperation("上传文件的方法")
    @PostMapping("/upload_picture")
    public ResponseResult upload_picture(@RequestBody MultipartFile multipartFile){
        return wmMaterialService.uploadPicture(multipartFile);
    }


    /**
     * 查询所有数据
     * @param dto
     * @return
     */
    @ApiOperation("显示数据")
    @PostMapping("/list")
    public PageResponseResult findList(@RequestBody WmMaterialDTO dto){
        return wmMaterialService.findList(dto);
    }



    /**
     * 删除
     * @param
     * @return
     */
    @ApiOperation("删除")
    @GetMapping("/del_picture/{id}")
    public ResponseResult del_picture(@PathVariable Integer id){
        return wmMaterialService.del_picture(id);
    }





    /**
     * 收藏
     * @param
     * @return
     */
    @ApiOperation("收藏")
    @GetMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable Integer id){
        return wmMaterialService.updateStatus(id, WemediaConstants.COLLECT_MATERIAL);
    }
    /**
     * 收藏
     * @param
     * @return
     */
    @ApiOperation("取消收藏")
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancel_collect(@PathVariable Integer id){
        return wmMaterialService.updateStatus(id,WemediaConstants.CANCEL_COLLECT_MATERIAL);
    }




}
